package mytest.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

public class Response {
	
	private Map<Object, Object> map;
	private List<HashMap<Object, Object>> list;
	private int retCode;
	private String retMessage;
	
	public Response() {
		map = new HashMap<Object, Object>();
		list = new ArrayList<HashMap<Object, Object>>();
		retCode = 0;
		retMessage = "";
	}
	
	public String toString() {
		map.put("data", list);
		if (list.size() > 0) {
			map.put("list", list);
		}
		map.put("count", list.size());
		map.put("code", retCode);
		map.put("msg", retMessage);
		JSONObject object = new JSONObject(map);
		return object.toString();
	}

	public List<HashMap<Object, Object>> getList() {
		return list;
	}

	public Response setList(List<HashMap<Object, Object>> list2) {
		this.list = list2;
		return this;
	}
	
	public int getRetCode() {
		return retCode;
	}

	public Response setRetCode(int retCode) {
		this.retCode = retCode;
		return this;
	}
	
	public Response setRetCodeFalse() {
		this.retCode = 1;
		return this;
	}

	public String getRetMessage() {
		return retMessage;
	}

	public Response setRetMessage(String retMessage) {
		this.retMessage = retMessage;
		return this;
	}
	
	public Response setFalse(String retMessage)  {
		return setRetCodeFalse().setRetMessage(retMessage);
	}
	
}
